/**
////////////////////////////////////////////////////////////////////////////////
//                                                                            // 
//  Copyright (c) 2013 Santiago Benito Rebollo. Eclipse Public License - v 1.0//
//  @author Santiago Benito Rebollo.                                          // 
//  santiago.benito.rebollo@gmail.com                                         //
//                                                                            //  
////////////////////////////////////////////////////////////////////////////////
//                                                                            //
// THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC// 
// LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM//
// CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.                      //
//                                                                            //
// A Contributor may choose to distribute the Program in object code form     //
// under its own license agreement, provided that:                            //
//                                                                            //
// a) it complies with the terms and conditions of this Agreement; and        //
// b) its license agreement:                                                  //
//                                                                            //
// i) effectively disclaims on behalf of all Contributors all warranties and  //
// conditions, express and implied, including warranties or conditions of     //  
// title and non-infringement, and implied warranties or conditions of        //
// merchantability and fitness for a particular purpose;                      //
// ii) effectively excludes on behalf of all Contributors all liability for   //
// damages, including direct, indirect, special, incidental and consequential //
// damages, such as lost profits;                                             //
// iii) states that any provisions which differ from this Agreement are       //
// offered by that Contributor alone and not by any other party; and          //
// iv) states that source code for the Program is available from such         //
// Contributor, and informs licensees how to obtain it in a reasonable        //
// manner on or through a medium customarily used for software exchange.      //
//                                                                            //
////////////////////////////////////////////////////////////////////////////////
 */

package com.chago.fastrecado;

import java.io.FileNotFoundException;
import java.util.NoSuchElementException;

/**
Specifies exceptions of any business rule process on the FastRecado project. 
This class is defined in the same way that its parent class. We have defined it 
just for avoiding dependence with its parent on the whole application. 
<p>Every time an instance (except when using the default constructor) 
of this class is created, it informs to the log file.</p>
@author <a href="mailto:santiago.benito.rebollo@gmail.com">Santiago Benito Rebollo </a>
@version 1.0
@see StandarErrorLog
@since 2013
 */
public class FastRecadoException extends Exception{

	private static final long serialVersionUID = 1L;
	/**
    *The error code. This will represent the key to be used for
    *looking on the bundle classes for the value of the given message.
    *Because this class could be used for sending a lot of different
    *business rule exceptions storing the code will be usefull for
    *identifying the error key.
    *@since 1.0
    */
   private String _code = "";
   
   /**
  * Initialize the parent information using the input arguments and set the corresponding instance fields. 
  * It informs on the log file about the stack trace. 
  * @param eventAction The action on the client size, see <a href="#eventAction"> <code>eventAction</code></a>.
  * @param code Code that identifies the message, see <a href="#code"> <code>code</code></a>.
  * @param message The message description associated with the exception, see <a href="#message"> <code>message</code></a>.    
  * @see StandardErrorLog
  * @since 1.0
  * @post $none
    */
   public FastRecadoException(int eventAction, String code, String message) {
             
       // Checking input arguments
       if (!ErrorCode.exist(eventAction)) {
           throw new NoSuchElementException(Integer.toString(eventAction));
       }
       setCode(code); // we check preconditions here
       // Printing the stack trace on the log file.        
       try {
    	   StandardLog log = new StandardLog();
    	   log.error(message);
       } catch (FileNotFoundException e) {
		e.printStackTrace();
       }
       
   }
   
   /**
   *    It is the same method, but with an extra param por detailed description. 
   *    @param eventAction The action on the client size, see <a href="#eventAction"> <code>eventAction</code></a>.
   *    @param code Code that identifies the message, see <a href="#code"> <code>code</code></a>.
   *    @param message The message description associated with the exception, see <a href="#message"> <code>message</code></a>.    
   *    @param message The message extended description associated with the exception, see <a href="#message"> <code>message</code></a>.  
   *    @see StandardErrorLog
   *    @since 1.0
   *    @post $none
    */
   public FastRecadoException(int eventAction, String code, String message, String detailedDescription) {
       
       // Checking the input values
       if (!ErrorCode.exist(eventAction)) {
           throw new NoSuchElementException(Integer.toString(eventAction));
       }
       // Printing the stack trace on the log file.
       setCode(code);
       // Printing the stack trace on the log file.        
       try {
    	   StandardLog log = new StandardLog();
    	   log.error(message);
    	   log.error(detailedDescription);
       } catch (FileNotFoundException e) {
		e.printStackTrace();
       }
   }    
               
   /**
   Default constructor, it just invokes the corresponding parent constructor.
   @post $none

    */
   public FastRecadoException() {
       super();     
   }
   
   /**
    Obtain the error code (exception code).
    @return The error code.
    @since 1.1
    @pre $none
    @post $none
   */
   public final String getCode() {
       return _code;
   }
   
   /**
    The the code error.
    @param value The error code to assign.
    @throws java.lang.NullPointerException If the input argument is 
    <code>null</code>.
    @throws java.lang.IllegalArgumentException If the input argument
    is the empty string.
    @since 1.1
    @pre $none
    @post $none
   */
   public final void setCode(String value) {
       // Checking preconditions
       _code = value;
   }
   
   

   
}
